#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import struct

def usage(arg0):
	print(f'usage: {arg0} <binary_file_to_process>')
	print('Convert binary file to C/C++ initialize list.')
	print('Will detect if "x86" or "x64" is in the binary file name, and output the corresponding length/alignment of the shellcode.')

def read_binary_file(filepath):
	with open(filepath, "rb") as f: data = f.read()
	position = 0;
	if '64' in filepath:
		while position < len(data):
			piece = data[position: position + 8]
			position += 8
			value = struct.unpack('<Q', piece)[0]
			print(f'0x{value:0{16}x},')
	else:
		while position < len(data):
			piece = data[position: position + 4]
			position += 4
			value = struct.unpack('<I', piece)[0]
			print(f'0x{value:0{8}x},')

if __name__ == '__main__':
	if len(sys.argv) < 2:
		usage(sys.argv[0])
		exit(1)
	read_binary_file(sys.argv[1])


